package fem2d;

import java.util.ArrayList;

import fem2.AbstractDemoWithGiD;
import fem2.AbstractSteadyHeatDemo;
import fem2.Constraint;
import fem2.Element;
import fem2.Mesh;
import fem2.MeshGenerator;
import fem2.MeshPart;
import fem2.MeshUtilities;
import fem2.Model;
import fem2.Node;
import fem2.element.PoissonElement;
import fem2.pre_and_post.PatchMeshGenerator;

public class TemperatureDistributionExample extends AbstractSteadyHeatDemo {

	private double k = 1e3;

	public TemperatureDistributionExample() {
		projectDir = "/home/hbui/kratos_janosch";
		projectName = "steady-heat.gid";
		meshFileName = "mesh10x10.msh";
	}

	@Override
	public Element createElement(MeshPart mp) {
		return new PoissonElement(mp, k);
	}

	@Override
	public Mesh createMesh() {
		MeshGenerator mg = new PatchMeshGenerator(11, 11, 0, 0, 1, 1);
		return mg.getMesh(2);
	}

	@Override
	public Model createConditions(Model m) {

		Mesh mesh = m.getMesh();

		ArrayList<Node> left = MeshUtilities.seekNodesOnLine(mesh, 0, 0, 0, 1);
		ArrayList<Node> right = MeshUtilities.seekNodesOnLine(mesh, 10, 0, 0, 1);
		ArrayList<Node> bottom = MeshUtilities.seekNodesOnLine(mesh, 0, 0, 1, 0);
		ArrayList<Node> top = MeshUtilities.seekNodesOnLine(mesh, 0, 10, 1, 0);

		Node n = MeshUtilities.seekNode(mesh, 5, 5);

		Constraint co = new Constraint(false);
		Constraint ci = new Constraint(false);

		co.setValue(0, 20);
		ci.setValue(0, 100);

		mesh.addConstraint(co, left);
		mesh.addConstraint(co, right);
		mesh.addConstraint(co, top);
		mesh.addConstraint(co, bottom);

		n.setConstraint(ci);

		return m;
	}

	public static void main(String[] args) {
		AbstractDemoWithGiD demo = new TemperatureDistributionExample();

		demo.run();
	}
}
